﻿Public Partial Class AssignMenuForRole
    Inherits System.Web.UI.Page
    Dim clsGet As New ClassFunctionGetData
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim lbPage As Label = CType(Master.FindControl("lbPage"), Label)
            lbPage.Text = "ACCESS ROLE MANAGEMENT "
            Dim clsGet As New ClassFunctionGetData()
            gridAssign.DataSource = clsGet.LoadRole()
            gridAssign.DataBind()
            If (Request.QueryString("P1") & "" = "Y") Then
                Session("EditMaster") = "Y"
            Else
                Session("EditMaster") = Nothing
            End If
        End If
    End Sub

    Protected Sub ddlPage_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        Dim Page As GridViewRow = gridAssign.BottomPagerRow
        Dim ddlPage As DropDownList = CType(Page.Cells(0).FindControl("ddlPage"), DropDownList)
        gridAssign.PageIndex = ddlPage.SelectedIndex
        gridAssign.DataSource = ViewState("Tariff")
        gridAssign.DataBind()
    End Sub

    Public Sub Paginate(ByVal sender As Object, ByVal e As CommandEventArgs)
        Dim CurrentIndex As Integer = gridAssign.PageIndex
        Select Case e.CommandArgument.ToString().ToLower()
            Case "first"
                gridAssign.PageIndex = 0
            Case "prev"
                If (gridAssign.PageIndex <> 0) Then
                    gridAssign.PageIndex = CurrentIndex - 1
                End If
            Case "next"
                If (gridAssign.PageIndex <> gridAssign.PageCount) Then
                    gridAssign.PageIndex = CurrentIndex + 1
                End If
            Case "last"
                gridAssign.PageIndex = gridAssign.PageCount
        End Select
        gridAssign.DataSource = ViewState("Tariff")
        gridAssign.DataBind()
    End Sub

    Private Sub gridAssign_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles gridAssign.RowCommand
        Dim Index As Integer = Convert.ToInt32(e.CommandArgument)
        If e.CommandName = "cmdedit" Then
            Session("Role_no") = gridAssign.DataKeys(Index).Values("Role_no")
            ModalPopupExtender1.Show()
        End If
    End Sub

    Private Sub gridAssign_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gridAssign.RowDataBound
        If (e.Row.RowType = DataControlRowType.Pager) Then
            Dim Page As GridViewRow = gridAssign.BottomPagerRow
            Dim ddlPage As DropDownList = CType(e.Row.FindControl("ddlPage"), DropDownList)
            Dim lblPageCount As Label = CType(e.Row.FindControl("lbPageCount"), Label)
            If Not (ddlPage Is Nothing) Then
                For i As Integer = 0 To gridAssign.PageCount - 1
                    Dim intPageNumber As Integer = i + 1
                    Dim IsItem As New ListItem(intPageNumber.ToString())
                    If (i = gridAssign.PageIndex) Then
                        IsItem.Selected = True
                    End If
                    ddlPage.Items.Add(IsItem)
                Next
            End If
            If Not (lblPageCount Is Nothing) Then
                lblPageCount.Text = gridAssign.PageCount.ToString()
            End If
        End If
    End Sub

    Private Sub MainPage_PreInit(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreInit
        Dim ds As DataSet = Session("UserData")
        If Not (ds Is Nothing) Then
            Page.MasterPageFile = clsGet.GetMaster_Page(ds.Tables(0).Rows(0).Item("User_Name").ToString(), "M")
        End If
    End Sub
End Class